-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
store TiDB server info to PD and add http api handle #7082
Conversation
|
b9f7388
to
1f44a8a
Compare
1f44a8a
to
24eea21
Compare
1fed1c2
to
159a7b4
Compare
ddl/ddl.go
Outdated
@@ -510,6 +525,46 @@ func (d *ddl) SetBinlogClient(binlogCli interface{}) { | |||
d.binlogCli = binlogCli | |||
} | |||
|
|||
func (d *ddl) GetServerInfo() *util.DDLServerInfo { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could write it like this.
func (d *ddl) GetServerInfo() *util.DDLServerInfo {
cfg := config.GetGlobalConfig()
info := &util.DDLServerInfo{
ID: d.uuid,
IP: cfg.AdvertiseAddress,
StatusPort: cfg.Status.StatusPort,
Lease: cfg.Lease,
}
info.Version = mysql.ServerVersion
info.GitHash = printer.TiDBGitHash
return info
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
8e9854a
to
256798e
Compare
ddl/ddl.go
Outdated
@@ -207,6 +209,15 @@ type DDL interface { | |||
|
|||
// SetBinlogClient sets the binlog client for DDL worker. It's exported for testing. | |||
SetBinlogClient(interface{}) | |||
|
|||
// GetServerInfo get self DDL server static information. | |||
GetServerInfo() *util.DDLServerInfo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not related with DDL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation should be updated?
ddl/ddl.go
Outdated
@@ -376,6 +387,10 @@ func (d *ddl) close() { | |||
if err != nil { | |||
log.Errorf("[ddl] remove self version path failed %v", err) | |||
} | |||
err = d.schemaSyncer.RemoveSelfServerInfo() | |||
if err != nil { | |||
log.Errorf("[ddl] remove self server info path failed %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove path
?
ddl/syncer.go
Outdated
@@ -20,11 +20,14 @@ import ( | |||
"sync" | |||
"time" | |||
|
|||
"encoding/json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put this line to line 17
ddl/syncer.go
Outdated
time.Sleep(200 * time.Millisecond) | ||
continue | ||
} | ||
if err == nil && len(resp.Kvs) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to check err == nil
here
ddl/syncer.go
Outdated
err := json.Unmarshal(resp.Kvs[0].Value, info) | ||
if err != nil { | ||
log.Infof("[syncer] get ddl server info, ddl %s json.Unmarshal %v failed %v.", resp.Kvs[0].Key, resp.Kvs[0].Value, err) | ||
return nil, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errors.Trace(err)
ddl/syncer.go
Outdated
err := json.Unmarshal(kv.Value, info) | ||
if err != nil { | ||
log.Infof("[syncer] get all ddl server info, ddl %s json.Unmarshal %v failed %v.", kv.Key, kv.Value, err) | ||
return nil, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errors.Trace(err)
Maybe it's better to specify what static information does this PR store to PD. |
ddl/syncer.go
Outdated
// GetAllServerInfoFromPD get all DDL servers information from PD. | ||
GetAllServerInfoFromPD(ctx context.Context) (map[string]*util.DDLServerInfo, error) | ||
// UpdateSelfServerInfo store DDL server information to PD. | ||
UpdateSelfServerInfo(ctx context.Context, info *util.DDLServerInfo) error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the info will not be updated during running,
I think that name it as StoreSelfServerInfoToPD is enough
@crazycs520 Please address the comments. |
domain/info.go
Outdated
} | ||
info, ok := infoMap[id] | ||
if !ok { | ||
return nil, errors.Errorf("[infoSyncer] get %s failed", key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "info-syncer" is better.
domain/info.go
Outdated
return errors.Trace(is.newSessionAndStoreServerInfo(ctx, owner.NewSessionDefaultRetryCnt)) | ||
} | ||
|
||
//GetServerInfo gets self server static information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s//Get
// Get
server/http_handler.go
Outdated
log.Error(err) | ||
return | ||
} | ||
ownerID, err := do.DDL().OwnerManager().GetOwnerID(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to add a timeout to ctx
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
ddl/syncer.go
Outdated
@@ -83,6 +83,8 @@ type SchemaSyncer interface { | |||
// the latest schema version. If the result is false, wait for a while and check again util the processing time reach 2 * lease. | |||
// It returns until all servers' versions are equal to the latest version or the ctx is done. | |||
OwnerCheckAllVersions(ctx context.Context, latestVer int64) error | |||
// GetSession return the session lease id of SchemaSyncer. | |||
GetSessionLeaseID() clientv3.LeaseID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/GetSessionLeaseID/GetLeaseID/
domain/info.go
Outdated
// InfoSessionTTL is the etcd session's TTL in seconds. It's exported for testing. | ||
var InfoSessionTTL = 10 * 60 | ||
|
||
// InfoSyncer stores server info to etcd when when the tidb-server starts and delete when tidb-server shuts down. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when when -> when
domain/info.go
Outdated
} | ||
|
||
// ServerInfo is server static information. | ||
// It will not update when server running. So please only put static information in ServerInfo struct. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/update/be updated/ or change
when server running -> during tidb-server process lifetime
StatusPort: cfg.Status.StatusPort, | ||
Lease: cfg.Lease, | ||
} | ||
info.Version = mysql.ServerVersion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not move the two lines into the above block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version
and GitHash
belong to ServerVersionInfo
. ServerInfo
contain ServerVersionInfo
with no attribute name.
ddl/syncer.go
Outdated
func (s *schemaVersionSyncer) putKV(ctx context.Context, retryCnt int, key, val string, | ||
// PutKVToEtcd puts key value to etcd. | ||
// etcdCli is client of etcd. | ||
// retryCnt is retry time when When an error occurs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/ when when / when
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
domain/info.go
Outdated
) | ||
|
||
// InfoSessionTTL is the etcd session's TTL in seconds. It's exported for testing. | ||
var InfoSessionTTL = 10 * 60 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 mins is long enough.
domain/info.go
Outdated
|
||
// Restart restart the info syncer with new session leaseID and store server info to etcd again. | ||
func (is *InfoSyncer) Restart(ctx context.Context) error { | ||
return errors.Trace(is.newSessionAndStoreServerInfo(ctx, owner.NewSessionRetryUnlimited)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use NewSessionRetryUnlimited?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see in schemaVersionSyncer. Restart()
use NewSessionRetryUnlimited when Restart
, so...
How about your option?
@shenli PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/run-all-tests |
1 similar comment
/run-all-tests |
3e4fa22
to
9831a1f
Compare
/run-all-tests |
* See pingcap/tidb#7082 for details of the API
* tidb: add info collected from TiDB's server API * See pingcap/tidb#7082 for details of the API * tidb: minor cleanup of pdctl code * tidb: check wheather tidb server api is supported * tidb: fix runtime error when collecting pdctl
What have you changed? (mandatory)
This PR is for issue#6961
{TiDBIP}:10080/info
request for TiDBIP server information.{TiDBIP}:10080/info/all
requSchemaSyncerest for all TiDB server information.What is the type of the changes? (mandatory)
How has this PR been tested? (mandatory)
add in tidb-test. https://github.com/pingcap/tidb-test/pull/593
Does this PR affect documentation (docs/docs-cn) update? (mandatory)
Yes
Does this PR affect tidb-ansible update? (mandatory)
Yes
Does this PR need to be added to the release notes? (mandatory)
Store TiDB information to PD and add http-api to get TiDB and cluster information.
Refer to a related PR or issue link (optional)
Benchmark result if necessary (optional)
Add a few positive/negative examples (optional)